import type {
  ActBarcodeModel,
  BarcodeAndScanPageRequest,
  KpcodeBarcodeDueEntity,
  KpcodeBarcodeScanEntity,
  PanicReservationBarcodeRequest,
  TotalCodeNum,
} from '@/types/code'
import type { PageResult, WxChatPayDto } from '@/types/global'
import type { UserJackItem } from '@/types/member'
import { http } from '@/utils/http'
import { buildGetRequest } from '@/utils/utils'

/**
 * 乐促码激活 弃用
 * @param data 请求参数
 */
export const postActBarcodeAPI = (data: ActBarcodeModel) => {
  return http({
    method: 'POST',
    url: '/admin/barcodeApi/actBarcode',
    data,
  })
}

/**
 * 商家的乐促码和扫描码分页列表
 * @param data 请求参数
 */

export const getBarcodeAndScanPageAPI = (urlStr: string) => {
  // const urlStr = buildGetRequest('/admin/barcodeApi/barcodeAndScanPage', data)
  return http<PageResult<KpcodeBarcodeScanEntity[]>>({
    method: 'GET',
    url: '/admin/barcodeApi/barcodeAndScanPage' + urlStr,
  })
}

// 商家的扫描码分页查询
export const getBarcodeScanPageAPI = (urlStr: string) => {
  return http<PageResult<KpcodeBarcodeScanEntity>>({
    method: 'GET',
    url: `/admin/barcodeApi/barcodeScanPage` + urlStr,
  })
}

/**
 * 查询乐促码预约列表
 * @param data 请求参数
 */

export const getBarcodeDuePageAPI = (areaCode: string) => {
  return http<PageResult<KpcodeBarcodeDueEntity>>({
    method: 'GET',
    url: `/admin/barcodeDueApi/reservationBarcodePage?status=0&areaCode=${areaCode}`,
  })
}

// 获取乐促码预约详情
export const getBarcodeReservationDetailAPI = (id: string) => {
  return http<KpcodeBarcodeDueEntity>({
    method: 'GET',
    url: '/admin/barcodeDueApi/getKpcodeBarcodeDueEntity?id=' + id,
  })
}

// 获取扫描乐促码详情
export const getBarcodeDetailAPI = (id: string) => {
  return http<KpcodeBarcodeScanEntity>({
    method: 'GET',
    url: '/admin/barcodeApi/getBarcodeScanById?id=' + id,
  })
}

// 我发的码-统计总数
export const getBarcodeTotalNumAPI = (urlStr: string) => {
  return http<TotalCodeNum>({
    method: 'GET',
    url: '/admin/barcodeApi/myBarcodeScanCount' + urlStr,
  })
}

// 按日期获取发码列表
export const getBarcodeByDateAPI = (urlStr: string) => {
  return http({
    method: 'GET',
    url: '/admin/barcodeApi/myBarcodeScanGroupDate' + urlStr,
  })
}

/**
 * 查询乐促码我的抢单列表
 * @param data 请求参数
 */

export const getBarcodeDueMyPageAPI = (agentId: string) => {
  return http<PageResult<KpcodeBarcodeDueEntity>>({
    method: 'GET',
    url: '/admin/barcodeDueApi/reservationBarcodePage?agentId=' + agentId,
  })
}

/**
 * 乐促码抢单
 * @param data 请求参数
 */

export const getPanicReservationBarcodeAPI = (data: PanicReservationBarcodeRequest) => {
  return http({
    method: 'POST',
    url: '/admin/barcodeDueApi/panicReservationBarcode',
    data,
  })
}

/**
 * 乐促码抢单数量查询
 * @param data 请求参数
 */

export const getReservationBarcodeCountAPI = (urlStr: string) => {
  return http({
    method: 'GET',
    url: '/admin/barcodeDueApi/reservationBarcodeCount' + urlStr,
  })
}

/**
 * 修改乐促码订单状态
 * @param data 请求参数
 */

export const postOrderStatusAPI = (data: any) => {
  return http<PageResult<KpcodeBarcodeDueEntity[]>>({
    method: 'POST',
    url: '/admin/barcodeDueApi/updateReservationBarcodeStatus',
    data
  })
}

/**
 * 计算乐促码需要支付的金额
 * @param data 请求参数
 */
export const getBarcodeAllPriceAPI = (data:{acsType:string,codeNo:string}) => {
  return http<string>({
    method: 'POST',
    url: '/admin/barcodeApi/getBarcodeAllPrice',
    data
  })
}

/**
 * 乐促码微信下单，生成微信订单
 * @param data 请求参数
 */
export const barcodeScanWxPayApi = (data: ActBarcodeModel) => {
  return http<WxChatPayDto>({
    method: 'POST',
    url: '/admin/barcodeScanWxPayApi/barcodeScanToPayOrder',
    data,
  })
}

/**
 * 生成微信订单后的回调函数
 * @param data 请求参数
 */
export const barcodeScanCallBack = () => {
  return http({
    method: 'GET',
    url: '/admin/barcodeScanWxPayApi/barcodeScanCallBack',
  })
}

/**
 * 乐促码绑定
 * @param data 请求参数
 */
export const bindBarcodeApi = (data: ActBarcodeModel) => {
  return http<string>({
    method: 'POST',
    url: '/admin/barcodeApi/bindBarcode',
    data,
  })
}
